{extend name="public:base"}
{block name='css'}
<link href="__PUBLIC__/css/plugins/iCheck/custom.css" rel="stylesheet">
{/block}
{block name="js"}
<script src="__PUBLIC__/js/plugins/peity/jquery.peity.min.js"></script>
<script src="__PUBLIC__/js/content.min.js?v=1.0.0"></script>
<script type="text/javascript">
    function setRun(self) {
        if ($(self).hasClass('ed')) {
            return false;
        }

        var id = $(self).attr('data-id');
        var state = $(self).attr('data-state');

        $(self).addClass('ed');
        $.post("{:url('state')}", {id:id,state:state}, function(data){
            layer.msg(data.info);
            if (data.status == 'y') {
                if (state == 1) {
                    $(self).attr('class', 'btn btn-primary btn-xs delete').attr('data-state', '2').text('启动');
                } else {
                    $(self).attr('class', 'btn btn-danger btn-xs edit').attr('data-state', '1').text('停止');
                }
            } else {
                $(self).removeClass('ed');
            }
        }, 'json');
    }
    function ajaxsubmit(self){
        if ($(self).hasClass('ed')) {
            return false;
        }
        $(self).addClass('ed');
        var obj = showMyLoading();
        $.post("{:url('saveSort')}", $(self).serialize(), function(data){
            hideMyLoading(obj);
            layer.msg(data.info);
            $(self).removeClass('ed');
            if (data.status == 'y') {
                setTimeout(function(){window.location.reload();},1500);
            }
        }, 'json');
    }
    function del(self, id){
        if ($(self).hasClass('ed')) {
            return false;
        }

        layer.confirm('真的要删除吗？删除后将无法找回！', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $(self).addClass('ed');
            var obj = showMyLoading();
            $.post("{:url('del')}", {id:id}, function(data){
                hideMyLoading(obj);
                layer.msg(data.info);
                if (data.status == 'y') {
                    setTimeout(function(){window.location.reload();},1500);
                } else {
                    $(self).removeClass('ed');
                }
            }, 'json');
        }, function(){

        });
    }
</script>
{/block}
{block name='body'}

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>内容管理</h5>
                    <a  href="javascript:;" data-toggle="modal" data-target="#add" class="btn btn-sm btn-primary pull-right m-t-n-xs">添加内容</a>
                </div>
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="row">
                            <form name="form" action="{:url('index')}" method="get">
                                <div class="col-sm-2 m-b-xs">
                                    <select class="form-control m-b" name="contentclass_id" style="height:30px;padding:4px 12px;">
                                        <option value="">内容分类！</option>
                                        {foreach name="contentClassList" item="li"}
                                        <option value="{$key}" {if condition="input('get.contentclass_id') eq $key"}selected="selected"{/if} >{$li}</option>
                                        {/foreach}
                                    </select>
                                </div>
                                <div class="col-sm-2 m-b-xs">
                                    <select class="form-control m-b" name="type" style="height:30px;padding:4px 12px;">
                                        <option value="">类型</option>
                                        <option value="1" {if condition="input('get.type') eq 1"}selected="selected"{/if}>HTML</option>
                                        <option value="2" {if condition="input('get.type') eq 2"}selected="selected"{/if}>URL</option>
                                        <option value="3" {if condition="input('get.type') eq 3"}selected="selected"{/if}>JSON</option>
                                        <option value="4" {if condition="input('get.type') eq 4"}selected="selected"{/if}>单图</option>
                                        <option value="5" {if condition="input('get.type') eq 5"}selected="selected"{/if}>多图</option>
                                    </select>
                                </div>
                                <div class="col-sm-2 m-b-xs">
                                    <select class="form-control m-b" name="state" style="height:30px;padding:4px 12px;">
                                        <option value="">状态！</option>
                                        <option value="1" {if condition="input('get.state') eq 1"}selected="selected"{/if} >已启动</option>
                                        <option value="2" {if condition="input('get.state') eq 2"}selected="selected"{/if} >已停止</option>
                                    </select>
                                </div>
                                <div class="col-sm-4 m-b-xs">
                                    <div class="input-group">
                                        <input type="text" name="keywords" value="{:input('get.keywords')}" placeholder="标题" class="input-sm form-control"> <span class="input-group-btn">
                                        <button type="submit"  class="btn btn-sm btn-primary"> 搜索</button>
                                        <a href="{:url('index')}" class="btn btn-sm btn-warning"> 重置</a> </span>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <form name="form" id="inform"  method="post" >
                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th>分类</th>
                                    <th>标题</th>
                                    <th>类型</th>
                                    <th>排序</th>
                                    <th>状态</th>
                                    <th>添加时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                {foreach name="list" item="li"}
                                <tr>
                                    <td>{$contentClassList[$li.contentclass_id]}</td>
                                    <td>{$li.title}</td>
                                    <td>
                                        {switch name="li.type"}
                                        {case value="1" break="1"}HTML{/case}
                                        {case value="2" break="1"}URL{/case}
                                        {case value="3" break="1"}JSON{/case}
                                        {case value="4" break="1"}单图{/case}
                                        {case value="5" break="1"}多图{/case}
                                        {/switch}
                                    </td>
                                    <td><input type="text"  style="width:60px;text-align:center;" name="{$li.id}" value="{$li.sort}" class="form-control"></td>
                                    <td>
                                        {if condition="$li['state'] eq 1"}
                                        <a href="javascript:;" onclick="setRun(this)" data-id="{$li.id}" data-state="2" class="btn btn-primary btn-xs edit">启动</a>
                                        {else/}
                                        <a href="javascript:;" onclick="setRun(this)" data-id="{$li.id}" data-state="1" class="btn btn-danger btn-xs delete">停止</a>
                                        {/if}
                                    </td>
                                    <td>{$li.time|date='Y-m-d H:i:s',###}</td>
                                    <td>
                                        <a  href="{:url('add',['id'=>$li['id']])}" class="btn btn-success btn-xs edit"><i class="fa fa-edit"></i> 编辑</a>
                                        <a href="javascript:;" onclick="del(this, {$li.id});" class="btn btn-danger btn-xs delete"><i class="fa fa-trash-o"></i> 删除</a>
                                    </td>
                                </tr>
                                {/foreach}
                                </tbody>
                                <tfoot>
                                <tr>
                                    <td colspan="3">&nbsp;</td>
                                    <td colspan="3">
                                        <input type="submit" onclick="ajaxsubmit('#inform');return false;" class="btn btn-sm btn-primary m-t-n-xs" value="修改排序" />
                                    </td>
                                    <td colspan="10">
                                        {$list->render()}
                                    </td>
                                </tr>
                                </tfoot>
                            </table>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="modal inmodal fade" id="add" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header" style="padding:15px;">
                    <button type="button" class="close closeReply" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" style="font-size:20px;">请选择类型</h4>
                </div>
                <form class="form-horizontal m-t"  id="signupForm" action="{:url('add')}"  method="get" onsubmit="return add();">
                    <input type="hidden" name="action" value="1" />
                    <div class="modal-body">
                        <select name="type" class="form-control">
                            <option value="1" >HTML</option>
                            <option value="2" >URL</option>
                            <option value="3" >JSON</option>
                            <option value="4" >单图</option>
                            <option value="5" >多图</option>
                        </select>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

</div>


</body>
{/block}
